/*
 * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef OHOS_CODEC_DATA
#define OHOS_CODEC_DATA

#include "ohosdec_common.h"

#include <multimedia/player_framework/native_avcodec_base.h>

namespace ohos {

AvBufferInfo::AvBufferInfo(int32_t indx, OH_AVBuffer *buff)
{
    index_ = indx;
    buff_ = buff;
}

AvBufferInfo::~AvBufferInfo()
{
}

int32_t AvBufferInfo::Index() const
{
    return index_;
}

uint8_t *AvBufferInfo::AvBufferAddr()
{
    AVCODEC_CHECK (buff_ == nullptr, "avbuffer is not initted!", nullptr);
    return OH_AVBuffer_GetAddr(buff_);
}

int32_t AvBufferInfo::Attr(OH_AVCodecBufferAttr *attr)
{
    AVCODEC_CHECK(attr == nullptr, "Attr is NULL", -1);
    AVCODEC_CHECK (buff_ == nullptr, "avbuffer is not initted!", -1);
    memcpy(&attr_, attr, sizeof(OH_AVCodecBufferAttr));

    return OH_AVBuffer_SetBufferAttr(buff_, attr);
}

const OH_AVCodecBufferAttr * const AvBufferInfo::Attr()
{
    if (OH_AVBuffer_GetBufferAttr(buff_, (OH_AVCodecBufferAttr *)&attr_) != AV_ERR_OK) {
        return nullptr;
    }

    return &attr_;
}

int32_t AvBufferInfo::AvBufferSize()
{
    AVCODEC_CHECK (buff_ == nullptr, "avbuffer is not initted!", -1);
    return OH_AVBuffer_GetCapacity(buff_);
}
} // namespace ohos

#endif // OHOS_CODC_DATA
